<template>
  <div class="home">
    <!-- 导航 -->
    <van-nav-bar title="我的收藏" left-arrow @click-left="$router.go(-1)" />
    <!-- 内容区 -->
    <div class="all" v-if="allList.length > 0">
      <div
        class="list"
        v-for="(item, index) in allList"
        :key="index"
        @click="goxqing(item.id)"
      >
        <div class="t1">{{ item.course_classify_title }}</div>
        <div class="t2">{{ item.title }}</div>
        <div class="t3">
          <van-tag
            round
            type="default"
            size="medium"
            v-for="(ite, ind) in item.course_label"
            :key="ind"
            style="margin-right: 10px"
            >{{ ite.label_name }}</van-tag
          >
        </div>
        <div class="t4">
          <div
            class="tu"
            v-for="(ite, ind) in item.teacher.slice(0, 3)"
            :key="ind"
          >
            <img :src="ite.avatar" alt="" class="img" />
            <div class="zi" style="margin-top: 10px">
              {{ ite.teacher_name }}
            </div>
          </div>
        </div>
        <div class="t5">
          <div class="dis">
            <div class="l">{{ item.sales_num }}人已报名</div>
            <div class="r" style="color: green" v-if="item.price == 0">
              免费
            </div>
            <div class="r" style="color: red" v-else>￥{{ item.price }}</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 空状态 -->
    <van-empty description="暂无该数据哦!" v-else />
  </div>
</template>

<script>
import { toRefs, reactive, onMounted } from 'vue'
import { getcollectApi } from '../http/api.js'
import { useRoute, useRouter } from 'vue-router'
export default {
  setup(props) {
    const route = useRoute()
    const router = useRouter()
    const data = reactive({
      allList: []
    })
    onMounted(() => {
      getgetcollect()
    })
    // 渲染数据
    const getgetcollect = async () => {
      const res = await getcollectApi()
      console.log('收藏的数据', res)
      data.allList = res.list
    }
    // 点击跳转到详情页面
    const goxqing = (id) => {
      router.push(`/xq?basis_id=${id}`)
    }
    return {
      ...toRefs(data),
      goxqing
    }
  }
}
</script>
<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
//   background-color: #eee;
  .all {
    width: 90%;
    box-sizing: border-box;
    padding: 20px 0;
	margin-left: 35px;
    .list {
      width: 100%;
      box-sizing: border-box;
      margin-bottom: 18px;
      padding-bottom: 20px;
      padding-top: 8px;
      box-shadow: 0 0 2px #ccc;
      .t1 {
        width: 18%;
        background-color: orangered;
        color: #fff;
        padding: 2px 15px;
        text-align: center;
        font-size: 12px;
        margin-left: 5px;
        border-top-left-radius: 20px;
        border-bottom-right-radius: 20px;
      }
      .t2,
      .t3,
      .t4,
      .t5 {
        margin-top: 25px;
        padding: 0 15px;
      }
      .t4 {
        width: 100%;
        box-sizing: border-box;
        display: flex;
        .tu {
          width: 33.3%;
          display: flex;
          .img {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            margin-right: 25px;
          }
        }
      }
      .t5 {
        width: 100%;
        box-sizing: border-box;
        .dis {
          width: 100%;
          box-sizing: border-box;
          display: flex;
          justify-content: space-between;
        }
      }
    }
  }
}
</style>
